package com.example.backweb.handler;

import com.example.backweb.common.exception.BaseException;
import com.example.backweb.common.exception.LoginExpiredException;
import com.example.backweb.common.exception.UnLoginException;
import com.example.backweb.common.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice
public class GlobalException {
    @ExceptionHandler(value = BaseException.class)
    public Result handler(BaseException e) {
        log.error("运行时异常：----------------{}", e.getMessage());
        return new Result().setCode(402).setMsg("无权限操作");
    }
    @ExceptionHandler(value = LoginExpiredException.class)
    public Result handler(LoginExpiredException e) {
        log.error("运行时异常：----------------{}", e.getMessage());
        return new Result().setCode(401).setMsg("登录已过期，请重新登录");
    }
    @ExceptionHandler(value = UnLoginException.class)
    public Result handler(UnLoginException e) {
        log.error("运行时异常：----------------{}", e);
        return new Result().setCode(401).setMsg("未登录");
    }
}
